<template>
	<view class="content">
		<view class="logo" style="">
			<image src="https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/logo.png"
				mode="widthFix" style="width: 30px;height: 30px;"></image>
			<view style="font-weight: 500;font-size: 22px;color: #FFFFFF;">
				求职精灵
			</view>
		</view>
		
		<view class="header">
		
		</view>
		<view class="foot">
			
		</view>
		<view class="center" >
				<image class="imageCl" src="https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/ai%20%281%29.png" 
					mode="widthFix" ></image>
				<view style="height: 70%;">
					
							<image  src="https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/%E5%9B%BE%E7%89%871.png" 
								mode="widthFix"  style="width: 160px;height:170px;margin-top: 40px;"></image>
				</view>
					<view class="submit" @click="login" open-type="exit">
					登录
					</view>
		</view>
		
		<view class="tag">
			<view style="background: linear-gradient(90deg, #6400FF 0% , #FF5EFD 100%);display: inline-block; color: transparent; -webkit-background-clip: text; background-clip: text;margin-left: 15px;">
				AI
			</view>
			<view style="  font-weight: 400; font-size: 15px; color: #282828; opacity: 0.8;">
				，让面试胸有成竹
			</view>
		</view>
	</view>
</template>

<script>
	// https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/%E5%9B%BE%E7%89%871.png
	import {
		scanlogin
	} from '../../api/index.js'
	
	export default {

		onLoad: function(options) {

			var scene = decodeURIComponent(options.scene)
			console.log('scene ==>', scene),
				this.scene = scene
				if(scene==null){
				}
				
				if (wx.setScreenBrightness) {
					// 保持屏幕常亮 true / false
					wx.setKeepScreenOn({
						keepScreenOn: true
					});
				} else {
					// 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
					wx.showModal({
						title: '提示',
						content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
					})
				}
				
				
				console.log("开始清除本地StorageSync")
				
				uni.clearStorageSync();
				
				
				console.log("清除本地StorageSync完成")
				

		},

		methods: {
			toRegister() {
				uni.navigateTo({
					url: '/pages/login/register'
				})
			},

			login: function() {
				var that = this
				uni.login({
					provider: 'weixin',
					success: function(resp) {
						scanlogin({
							wxCode: resp.code,
							qrCode: that.scene,

						}).then(
							res => {
								console.log(res, 'loginScan');
								uni.showToast({
									title: '登录成功',
									icon: 'success',
									duration: 2000
								});
								setTimeout(function() {
									// 在2秒后跳转到指定页面
								 
								
								}, 1000);

							}).catch((err) => {
							uni.showModal({
								title: '用户注册',
								content: '如果注册，我们将为您创建一个新账户。',
								success: function(modalRes) {
									if (modalRes.confirm) {
										// 用户点击了确定按钮，执行注册操作
										console.log('用户选择注册');
										// 跳转到注册页面
										uni.navigateTo({
											url: '/pages/register/register?scene=' +
												that.scene
										});
									} else if (modalRes.cancel) {
										// 用户点击了取消按钮，执行其他操作
										console.log('用户选择不注册');
										// 根据需要进行其他操作或直接关闭弹窗
									}
								},
								fail: function(err) {
									// 弹窗显示失败的处理逻辑
									console.error(err);
								}
							});
						})
					}


				});
			},
			exit() {
				// 如果状态为 wait 说明用户 未认证点击了取消登录
				if (this.status === 'wait') {
					// 我们就需要发送请求，将数据库状态修改为 cancel，在执行退出
					wx.request({
						url: this.data.baseUrl + 'user/cancel',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							scene: this.data.scene
						},
						success: resp => {
							// 执行退出小程序
							wx.exitMiniProgram({
								success: res => {
									console.log(res)
								}
							})
						}
					})
				} else {
					//否则，说明已认证，直接退出小程序即可
					wx.exitMiniProgram({
						success: res => {
							console.log(res)
						}
					})

				}
			}
		}
	}
</script>

<style lang="less">
	.content{
		position: relative;
		background: #E4E4FF;
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.logo{
			position: absolute;
			    top: -24%;
			    display: flex;
			    justify-content: center;
				align-items: center;
		}
		.header{
			background: url(https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/%E5%9B%BE%E5%B1%82%203%402x.png) no-repeat;
			background-size: cover;
			height: 40%;
		}
		.foot{
			background: url(https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/%E5%9B%BE%E5%B1%82%205.png) no-repeat;
			background-size: cover;
			height: 40%;
		}
		 .tag{
		        background: url(https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2%206.png) no-repeat;
		        position: absolute;
		        bottom: 5%;
		        width: 44%;
		        height: 35px;
				line-height: 28px;
		        background-size: cover;
				left:50%;
				transform:translateX(-50%);
				display: flex;

		  }

		.center{
			padding: 30px 10px;
			position: absolute;
			top: 26%;
			height: 50%;
			width: 80%;
			left:50%;
			transform:translateX(-50%);
			background: #FFFFFF;
			box-shadow: 0px 0px 65px 0px rgba(134,103,223,0.29);
			border-radius: 10px;
			border: 4px solid #FFFFFF;
			display: flex;
			flex-direction: column;
			align-items: center;
			.imageCl{
				width:40%;
				position: absolute;
				left:50%;
				transform:translateX(-50%);
				top: -20%;
			}
			.job{
				width: 100%;
				// background: rgba(178,143,255,0.1);
				// border-radius: 10px;
				// border: 1px solid #5125B2;
			}
			.submit{
				width: 100%;
				height: 50px;
				background: #7349E4;
				border-radius: 10px;
				border: 4px solid #FFFFFF;
				text-align: center;
				line-height: 50px;
				font-weight: 500;
				font-size: 20px;
				color: #FFFFFF;
				margin-top: 40px;
			}
			// .line{
			// 	width: 100%;
			// 	text-align: center;
			// }
			// .myinput{

			// }
			// .logo{
			// 	background: url(https://aiinterview-1322700550.cos.ap-shanghai.myqcloud.com/wxminiprograme/ai%20%281%29.png") no-repeat;
			// 	background-size: cover;
			// 	height: 204px;
			// 	width: 193px;
			// }
		}
	}
	
</style>